package com.hly.product.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Date;

/**
 * @program: Exercise01
 * Author HLY
 * @desc
 * @create: 2021-03-30 10:26
 **/
// 扫描我们的 mapper 文件夹
@MapperScan("com.hly.product.dao")
@EnableTransactionManagement //开启事务管理
@Configuration // 配置类
@Slf4j
public class MyBatisPlusConfig implements MetaObjectHandler {

    // 分页插件
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("嘟嘟噜~-保存");
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("嘟嘟噜~-更新");
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }


}